rm(list =ls())
options(scipen=999)
gc()
packages <-c("tidyverse","estimatr","plm","stargazer",
             "fastDummies","ICCbin","ihs","readstata13","xtable")

new.packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)

lapply(packages, require, character.only = TRUE)
rm(packages, new.packages)

setwd("PUT YOUR DIRECTORY HERE")

# load data
data <- read.csv("./Datasets/main_confounders.csv")

## rearrange variables, scale, etc.
data <- data%>%
  dplyr::mutate(across(subbotnik_inkind_1975:subbotnik_inkind_1979, ~scale(.x)))%>%
  dplyr::rowwise()%>%
  dplyr::mutate(commander_1975_79 = mean(c(commanders1975, commanders1976, 
                                           commanders1977, commanders1978,
                                           commanders1979), na.rm = TRUE))%>%
  dplyr::mutate(compliance = mean(c(subbotnik_inkind_1975, subbotnik_inkind_1976, 
                                    subbotnik_inkind_1977, subbotnik_inkind_1978,
                                    subbotnik_inkind_1979), na.rm = TRUE))%>%
  dplyr::ungroup()%>%
  dplyr::mutate(sabotage_commander_1975_79 = scale(sabotage_commander_1975_79),
                commander_1975_79 = scale(commander_1975_79),
                strikes = scale(strikes),
                sabotage = scale(compliance * -1))


## run models
lm_sabotage_1 <- lm(sabotage ~ sabotage_commander_1975_79, data = data)
lm_sabotage_2 <- lm(sabotage ~ sabotage_commander_1975_79 + commander_1975_79, data = data)

